package ac.beiwo.baas.user.controller;

import ac.beiwo.baas.common.entity.SimpleError;
import ac.beiwo.baas.common.entity.SimpleResult;
import ac.beiwo.baas.user.entity.BaasInstallation;
import ac.beiwo.baas.user.service.InstallationService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Staryet on 15/8/13.
 */
@RestController
@RequestMapping(value = "/installation")
public class InstallationController {

    @Autowired
    private InstallationService installationService;

    /**
     * 注册设备
     *
     * @param body
     * @return
     * @throws SimpleError
     */
    @RequestMapping(value = "/", method = RequestMethod.POST)
    @ResponseBody
    public SimpleResult insert(@RequestBody String body) throws SimpleError {
        JSONObject json = (JSONObject) JSON.parse(body);
        BaasInstallation installation = new BaasInstallation(json);
        String id = installationService.register(installation);
        SimpleResult result = SimpleResult.success();
        result.putData("id", id);
        return result;
    }

}
